# -*- coding: utf-8 -*-
"""
城市信息工具类，提供城市相关信息的查询功能

@Author: rslai
@Email: netlrs@163.com
@Date: 2025-09-19
"""

class CityUtils:
    """
    城市信息工具类，提供城市相关信息的查询功能
    """
    
    # 城市数据字典
    _city_data = {
        "北京": {"CityCode": "BJS", "Country": "中国"},
        "上海": {"CityCode": "SHA", "Country": "中国"},
        "广州": {"CityCode": "CAN", "Country": "中国"},
        "深圳": {"CityCode": "SZX", "Country": "中国"},
        "成都": {"CityCode": "CTU", "Country": "中国"},
        "香港": {"CityCode": "HKG", "Country": "中国"},
        "重庆": {"CityCode": "CKG", "Country": "中国"},
        "厦门": {"CityCode": "XMN", "Country": "中国"},
        "昆明": {"CityCode": "KMG", "Country": "中国"},
        "杭州": {"CityCode": "HGH", "Country": "中国"},
        "西安": {"CityCode": "SIA", "Country": "中国"},
        "武汉": {"CityCode": "WUH", "Country": "中国"},
        "长沙": {"CityCode": "CSX", "Country": "中国"},
        "南京": {"CityCode": "NKG", "Country": "中国"},
        "大连": {"CityCode": "DLC", "Country": "中国"},
        "郑州": {"CityCode": "CGO", "Country": "中国"},
        "青岛": {"CityCode": "TAO", "Country": "中国"},
        "天津": {"CityCode": "TSN", "Country": "中国"},
        "三亚": {"CityCode": "SYX", "Country": "中国"},
        "海口": {"CityCode": "HAK", "Country": "中国"},
        "安庆": {"CityCode": "AQG", "Country": "中国"},
        "阿勒泰": {"CityCode": "AAT", "Country": "中国"},
        "安康": {"CityCode": "AKA", "Country": "中国"},
        "阿克苏": {"CityCode": "AKU", "Country": "中国"},
        "安顺": {"CityCode": "AVA", "Country": "中国"},
        "包头": {"CityCode": "BAV", "Country": "中国"},
        "北海": {"CityCode": "BHY", "Country": "中国"},
        "百色": {"CityCode": "AEB", "Country": "中国"},
        "保山": {"CityCode": "BSD", "Country": "中国"},
        "长治": {"CityCode": "CIH", "Country": "中国"},
        "长春": {"CityCode": "CGQ", "Country": "中国"},
        "常州": {"CityCode": "CZX", "Country": "中国"},
        "昌都": {"CityCode": "BPX", "Country": "中国"},
        "朝阳": {"CityCode": "CHG", "Country": "中国"},
        "常德": {"CityCode": "CGD", "Country": "中国"},
        "长白山": {"CityCode": "NBS", "Country": "中国"},
        "赤峰": {"CityCode": "CIF", "Country": "中国"},
        "潮州": {"CityCode": "SWA", "Country": "中国"},
        "大同": {"CityCode": "DAT", "Country": "中国"},
        "达县": {"CityCode": "DAX", "Country": "中国"},
        "东营": {"CityCode": "DOY", "Country": "中国"},
        "大庆": {"CityCode": "DQA", "Country": "中国"},
        "丹东": {"CityCode": "DDG", "Country": "中国"},
        "大理": {"CityCode": "DLU", "Country": "中国"},
        "敦煌": {"CityCode": "DNH", "Country": "中国"},
        "稻城": {"CityCode": "DCY", "Country": "中国"},
        "鄂尔多斯": {"CityCode": "DSN", "Country": "中国"},
        "恩施": {"CityCode": "ENH", "Country": "中国"},
        "福州": {"CityCode": "FOC", "Country": "中国"},
        "阜阳": {"CityCode": "FUG", "Country": "中国"},
        "贵阳": {"CityCode": "KWE", "Country": "中国"},
        "桂林": {"CityCode": "KWL", "Country": "中国"},
        "广元": {"CityCode": "GYS", "Country": "中国"},
        "格尔木": {"CityCode": "GOQ", "Country": "中国"},
        "固原": {"CityCode": "GYU", "Country": "中国"},
        "呼和浩特": {"CityCode": "HET", "Country": "中国"},
        "哈密": {"CityCode": "HMI", "Country": "中国"},
        "黑河": {"CityCode": "HEK", "Country": "中国"},
        "海拉尔": {"CityCode": "HLD", "Country": "中国"},
        "哈尔滨": {"CityCode": "HRB", "Country": "中国"},
        "黄山": {"CityCode": "TXN", "Country": "中国"},
        "邯郸": {"CityCode": "HDG", "Country": "中国"},
        "合肥": {"CityCode": "HFE", "Country": "中国"},
        "汉中": {"CityCode": "HZG", "Country": "中国"},
        "和田": {"CityCode": "HTN", "Country": "中国"},
        "晋江": {"CityCode": "JJN", "Country": "中国"},
        "九寨沟": {"CityCode": "JZH", "Country": "中国"},
        "锦州": {"CityCode": "JNZ", "Country": "中国"},
        "景德镇": {"CityCode": "JDZ", "Country": "中国"},
        "嘉峪关": {"CityCode": "JGN", "Country": "中国"},
        "井冈山": {"CityCode": "JGS", "Country": "中国"},
        "济宁": {"CityCode": "JNG", "Country": "中国"},
        "九江": {"CityCode": "JIU", "Country": "中国"},
        "佳木斯": {"CityCode": "JMU", "Country": "中国"},
        "济南": {"CityCode": "TNA", "Country": "中国"},
        "揭阳": {"CityCode": "SWA", "Country": "中国"},
        "喀什": {"CityCode": "KHG", "Country": "中国"},
        "康定": {"CityCode": "KGT", "Country": "中国"},
        "克拉玛依": {"CityCode": "KRY", "Country": "中国"},
        "库尔勒": {"CityCode": "KRL", "Country": "中国"},
        "库车": {"CityCode": "KCA", "Country": "中国"},
        "兰州": {"CityCode": "LHW", "Country": "中国"},
        "洛阳": {"CityCode": "LYA", "Country": "中国"},
        "丽江": {"CityCode": "LJG", "Country": "中国"},
        "林芝": {"CityCode": "LZY", "Country": "中国"},
        "柳州": {"CityCode": "LZH", "Country": "中国"},
        "泸州": {"CityCode": "LZO", "Country": "中国"},
        "连云港": {"CityCode": "LYG", "Country": "中国"},
        "黎平": {"CityCode": "HZH", "Country": "中国"},
        "连城": {"CityCode": "LCX", "Country": "极"},
        "拉萨": {"CityCode": "LXA", "Country": "中国"},
        "临沧": {"CityCode": "LNJ", "Country": "中国"},
        "临沂": {"CityCode": "LYI", "Country": "中国"},
        "牡丹江": {"CityCode": "MDG", "Country": "中国"},
        "芒市": {"CityCode": "LUM", "Country": "中国"},
        "满洲里": {"CityCode": "NZH", "Country": "中国"},
        "绵阳": {"CityCode": "MIG", "Country": "中国"},
        "梅县": {"CityCode": "MXZ", "Country": "中国"},
        "漠河": {"CityCode": "OHE", "Country": "中国"},
        "南充": {"CityCode": "极", "Country": "中国"},
        "南宁": {"CityCode": "NNG", "Country": "中国"},
        "南阳": {"CityCode": "NNY", "Country": "中国"},
        "南通": {"CityCode": "NTG", "Country": "中国"},
        "那拉提": {"CityCode": "NLT", "Country": "中国"},
        "南昌": {"CityCode": "KHN", "Country": "中国"},
        "宁波": {"CityCode": "NGB", "Country": "中国"},
        "攀枝花": {"CityCode": "PZI", "Country": "中国"},
        "衢州": {"CityCode": "JUZ", "Country": "中国"},
        "秦皇岛": {"CityCode": "SHP", "Country": "中国"},
        "庆阳": {"CityCode": "IQN", "Country": "中国"},
        "齐齐哈尔": {"CityCode": "NDG", "Country": "中国"},
        "石家庄": {"CityCode": "SJW", "Country": "中国"},
        "思茅": {"CityCode": "SYM", "Country": "中国"},
        "汕头": {"CityCode": "SWA", "Country": "中国"},
        "铜仁": {"CityCode": "TEN", "Country": "中国"},
        "塔城": {"CityCode": "TCG", "Country": "中国"},
        "腾冲": {"CityCode": "TCZ", "Country": "中国"},
        "台州": {"CityCode": "HYN", "Country": "中国"},
        "通辽": {"CityCode": "TGO", "Country": "中国"},
        "太原": {"CityCode": "TYN", "Country": "中国"},
        "威海": {"CityCode": "WEH", "Country": "中国"},
        "梧州": {"CityCode": "WUZ", "Country": "中国"},
        "文山": {"CityCode": "WNH", "Country": "中国"},
        "无锡": {"CityCode": "WUX", "Country": "中国"},
        "潍坊": {"CityCode": "WEF", "Country": "中国"},
        "武夷山": {"CityCode": "极", "Country": "中国"},
        "乌兰浩特": {"CityCode": "HLH", "Country": "中国"},
        "温州": {"CityCode": "WNZ", "Country": "中国"},
        "乌鲁木齐": {"CityCode": "URC", "Country": "中国"},
        "万州": {"CityCode": "WXN", "Country": "中国"},
        "乌海": {"CityCode": "WUA", "Country": "中国"},
        "兴义": {"CityCode": "ACX", "Country": "中国"},
        "西昌": {"CityCode": "XIC", "Country": "中国"},
        "襄樊": {"CityCode": "XFN", "Country": "中国"},
        "西极": {"CityCode": "XNN", "Country": "中国"},
        "锡林浩特": {"CityCode": "XIL", "Country": "中国"},
        "西双版纳": {"CityCode": "JHG", "Country": "中国"},
        "徐州": {"CityCode": "XUZ", "Country": "中国"},
        "义乌": {"CityCode": "YIW", "Country": "中国"},
        "永州": {"CityCode": "LLF", "Country": "中国"},
        "榆林": {"CityCode": "UYN", "Country": "中国"},
        "延安": {"CityCode": "ENY", "Country": "中国"},
        "运城": {"CityCode": "YCU", "Country": "中国"},
        "烟台": {"CityCode": "YNT", "Country": "中国"},
        "银川": {"CityCode": "INC", "Country": "中国"},
        "宜昌": {"CityCode": "YIH", "Country": "中国"},
        "宜宾": {"CityCode": "YBP", "Country": "中国"},
        "盐城": {"CityCode": "YNZ", "Country": "中国"},
        "延吉": {"CityCode": "YNJ", "Country": "中国"},
        "玉树": {"CityCode": "YUS", "Country": "中国"},
        "伊宁": {"CityCode": "YIN", "Country": "中国"},
        "珠海": {"CityCode": "ZUH", "Country": "中国"},
        "昭通": {"CityCode": "ZAT", "Country": "中国"},
        "张家界": {"CityCode": "DYG", "Country": "中国"},
        "舟山": {"CityCode": "HSN", "Country": "中国"},
        "中卫": {"CityCode": "ZHY", "Country": "中国"},
        "芷江": {"CityCode": "HJJ", "Country": "中国"},
        "湛江": {"CityCode": "ZHA", "Country": "中国"},
        "中国香港": {"CityCode": "HKG", "Country": "中国"},
        "中国澳门": {"CityCode": "MFM", "Country": "中国"},
        "中国台北": {"CityCode": "TPE", "Country": "中国"},
        "中国高雄": {"CityCode": "KHH", "Country": "中国"},
        "新加坡": {"CityCode": "SIN", "Country": "新加坡"},
        "雅加达": {"CityCode": "JKT", "Country": "印度尼西亚"},
        "巴厘岛": {"CityCode": "DPS", "Country": "印度尼西亚"},
        "曼谷": {"CityCode": "BKK", "Country": "泰国"},
        "普吉岛": {"CityCode": "HKT", "Country": "泰国"},
        "马尼拉": {"CityCode": "MNL", "Country": "菲律宾"},
        "东京": {"CityCode": "TYO", "Country": "日本"},
        "大阪": {"CityCode": "OSA", "Country": "日本"},
        "吉隆坡": {"CityCode": "KUL", "Country": "马来西亚"},
        "金边": {"CityCode": "PNH", "Country": "柬埔寨"},
        "洛杉矶": {"CityCode": "LAX", "Country": "美国"},
        "纽约": {"CityCode": "NYC", "Country": "美国"},
        "旧金山": {"CityCode": "SFO", "Country": "美国"},
        "胡志明市": {"CityCode": "SGN", "Country": "越南"},
        "迪拜": {"CityCode": "DXB", "Country": "阿联酋"},
        "伦敦": {"CityCode": "LON", "Country": "英国"},
        "巴黎": {"CityCode": "PAR", "Country": "法国"},
        "温哥华": {"CityCode": "YVR", "Country": "加拿大"},
        "悉尼": {"CityCode": "SYD", "Country": "澳大利亚"},
        "墨尔本": {"CityCode": "MEL", "Country": "澳大利亚"},
        "首尔": {"CityCode": "SEL", "Country": "韩国"},
        "济州岛": {"CityCode": "CJU", "Country": "韩国"},
        "釜山": {"CityCode": "PUS", "Country": "韩国"},
        "清迈": {"CityCode": "CNX", "Country": "泰国"},
        "苏梅岛": {"CityCode": "USM", "Country极": "泰国"},
        "暹粒": {"CityCode": "REP", "Country": "柬埔寨"},
        "名古屋": {"CityCode": "NGO", "Country": "日本"},
        "河内": {"CityCode": "HAN", "Country": "越南"},
        "马累": {"CityCode": "MLE", "Country": "马尔代夫"},
        "福冈": {"CityCode": "FUK", "Country": "日本"},
        "德里": {"CityCode": "DEL", "Country": "印度"},
        "札幌": {"CityCode": "SPK", "Country": "日本"},
        "伊斯坦布尔": {"CityCode": "IST", "Country": "土耳其"},
        "乌兰巴托": {"CityCode": "ULN", "Country": "蒙古"},
        "孟买": {"CityCode": "BOM", "Country": "印度"},
        "奥克兰": {"CityCode": "AKL", "Country": "新西兰"},
        "布里斯班": {"CityCode": "BNE", "Country": "澳大利亚"},
        "珀斯": {"CityCode": "PER", "Country": "澳大利亚"},
        "阿德莱德": {"CityCode": "ADL", "Country": "澳大利亚"},
        "惠林顿": {"CityCode": "HLG", "Country": "新西兰"},
        "堪培拉": {"CityCode": "CBR", "Country": "澳大利亚"},
        "达尔文": {"CityCode": "DRW", "Country": "澳大利亚"},
        "凯恩斯": {"CityCode": "CNS", "Country": "澳大利亚"},
        "南迪": {"CityCode": "NAN", "Country": "斐济"},
        "黄金海岸": {"CityCode": "OOL", "Country": "澳大利亚"},
        "帕皮提": {"CityCode": "PPT", "Country": "法属波利尼西亚"},
        "法兰克福": {"CityCode": "FRA", "Country": "德国"},
        "慕尼黑": {"CityCode": "MUC", "Country": "德国"},
        "阿姆斯特丹": {"CityCode": "AMS", "Country": "荷兰"},
        "斯德哥尔摩": {"CityCode": "STO", "Country": "瑞典"},
        "巴塞罗那": {"CityCode": "BCN", "Country": "西班牙"},
        "柏林": {"CityCode": "BER", "Country": "德国"},
        "米兰": {"CityCode": "MIL", "Country": "意大利"},
        "莫斯科": {"CityCode": "MOW", "Country": "俄罗斯"},
        "罗马": {"CityCode": "ROM", "Country": "意大利"},
        "哥本哈根": {"CityCode": "CPH", "Country": "丹麦"},
        "布鲁塞尔": {"CityCode": "BRU", "Country": "比利时"},
        "杜塞尔多夫": {"CityCode": "DUS", "Country": "德国"},
        "汉堡": {"CityCode": "HAM", "Country": "德国"},
        "里昂": {"CityCode": "LYS", "Country": "法国"},
        "曼彻斯特": {"CityCode": "MAN", "Country": "英国"},
        "马德里": {"CityCode": "MAD", "Country": "西班牙"},
        "苏黎世": {"CityCode": "ZRH", "Country": "瑞士"},
        "赫尔辛极": {"CityCode": "HEL", "Country": "芬兰"},
        "日内瓦": {"CityCode": "GVA", "Country": "瑞士"},
        "圣彼得堡": {"CityCode": "LED", "Country": "俄罗斯"},
        "维也纳": {"CityCode": "VIE", "Country": "奥地利"},
        "雅典": {"CityCode": "ATH", "Country": "希腊"},
        "基辅": {"CityCode": "IEV", "Country": "乌克兰"},
        "布达佩斯": {"CityCode": "BUD", "Country": "匈牙利"},
        "布拉格": {"CityCode": "PRG", "Country": "捷克"},
        "芝加哥": {"CityCode": "CHI", "Country": "美国"},
        "多伦多": {"CityCode": "YTO", "Country": "加拿大"},
        "西雅图": {"CityCode": "SEA", "Country": "美国"},
        "华盛顿": {"CityCode": "WAS", "Country": "美国"},
        "波士顿": {"CityCode": "BOS", "Country": "美国"},
        "底特律": {"CityCode": "DTT", "Country": "美国"},
        "亚特兰大": {"CityCode": "ATL", "Country": "美国"},
        "休斯顿": {"CityCode": "HOU", "Country": "美国"},
        "费城": {"CityCode": "PHL", "Country": "美国"},
        "圣保罗": {"CityCode": "SAO", "Country": "巴西"},
        "渥太华": {"CityCode": "YOW", "Country": "加拿大"},
        "墨西哥城": {"CityCode": "MEX", "Country": "墨西哥"},
        "拉斯维加斯": {"CityCode": "LAS", "Country": "美国"},
        "迈阿密": {"CityCode": "MIA", "Country": "美国"},
        "丹佛": {"CityCode": "DEN", "Country": "美国"},
        "奥兰多": {"CityCode": "ORL", "Country": "美国"},
        "波特兰": {"CityCode": "PDX", "Country": "美国"},
        "埃德蒙顿": {"CityCode": "YEA", "Country": "加拿大"},
        "布宜诺斯": {"CityCode": "BUE", "Country": "阿根廷"},
        "蒙特利尔": {"CityCode": "YMQ", "Country": "加拿大"},
        "夏威夷": {"CityCode": "HNL", "Country": "美国"},
        "达拉斯": {"CityCode": "DFW", "Country": "美国"},
        "开罗": {"CityCode": "CAI", "Country": "埃及"},
        "约翰内斯堡": {"CityCode": "JNB", "Country": "南非"},
        "开普敦": {"CityCode": "CPT", "Country": "南非"},
        "内罗毕": {"CityCode": "NBO", "Country": "肯尼亚"},
        "拉各斯": {"CityCode": "LOS", "Country": "尼日利亚"},
        "毛里求斯": {"CityCode": "MRU", "Country": "毛里求斯"},
        "罗安达": {"CityCode": "LAD", "Country": "安哥拉"},
        "喀土穆": {"CityCode": "KRT", "Country": "苏丹"},
        "阿克拉": {"CityCode": "ACC", "Country": "加纳"},
        "阿尔及尔": {"CityCode": "ALG", "Country": "阿尔及利亚"},
        "卡萨布兰卡": {"CityCode": "CAS", "Country": "摩洛哥"},
        "德班": {"CityCode": "DUR", "Country": "南非"},
        "突尼斯": {"CityCode": "TUN", "Country": "突尼斯"},
        "卢萨卡": {"CityCode": "LUN", "Country": "赞比亚"},
        "哈拉雷": {"CityCode": "HRE", "Country": "津巴布韦"},
        "马普托": {"CityCode": "MPM", "Country": "莫桑比克"},
        "阿比让": {"CityCode": "ABJ", "Country": "科特迪瓦"}
    }
    
    _country_data = {
        "中国": [
            "北京",
            "天津",
            "石家庄",
            "上海",
            "广州",
            "深圳",
            "成都",
            "昆明",
            "重庆",
            "西安",
            "杭州",
            "厦门",
            "南京",
            "武汉",
            "乌鲁木齐",
            "海口",
            "三亚",
            "哈尔滨",
        ],
        "澳大利亚": [
            "悉尼",
            "墨尔本",
            "布里斯班",
            "珀斯",
            "阿德莱德",
            "黄金海岸",
            "凯恩斯",
            "达尔文",
            "堪培拉"
        ],
        "荷兰": [],
        "瑞典": [],
        "西班牙": [],
        "德国": [],
        "意大利": [],
        "俄罗斯": [],
        "英国": [],
        "芬兰": [],
        "瑞士": [],
        "匈牙利": [],
        "捷克": [],
        "美国": [
            "亚特兰大",
            "洛杉矶",
            "芝加哥",
            "达拉斯",
            "纽约",
            "旧金山",
            "西雅图",
            "迈阿密",
            "丹佛"
        ],
        "加拿大": [],
        "巴西": [],
        "墨西哥": [],
        "阿根廷": [],
        "安哥拉": [],
        "苏丹": [],
        "加纳": [],
        "阿尔及利亚": [],
        "摩洛哥": [],
        "南非": [],
        "突尼斯": [],
        "赞比亚": [],
        "津巴布韦": [],
        "莫桑比克": [],
    }


    @classmethod
    def get_city_info(cls, city_name):
        """
        根据城市名称获取城市信息
        
        Args:
            city_name (str): 城市名称（中文或英文）
            
        Returns:
            dict: 城市信息字典，包含CityCode、EnglishName和Country字段
                  如果城市不存在，返回None
        """
        # 先尝试直接查找（中文名称）
        if city_name in cls._city_data:
            return cls._city_data[city_name]
        
        # 尝试通过英文名称查找（不区分大小写）
        english_name_lower = city_name.lower()
        if english_name_lower in cls._english_to_local:
            local_name = cls._english_to_local[english_name_lower]
            return cls._city_data[local_name]
        
        # 城市不存在
        return None
    
    @classmethod
    def get_city_code(cls, city_name):
        """
        根据城市名称获取城市代码
        
        Args:
            city_name (str): 城市名称（中文或英文）
            
        Returns:
            str: 城市代码，如果城市不存在则返回None
        """
        city_info = cls.get_city_info(city_name)
        return city_info.get("CityCode") if city_info else None
    
    @classmethod
    def get_country(cls, city_name):
        """
        根据城市名称获取所在国家
        
        Args:
            city_name (str): 城市名称（中文或英文）
            
        Returns:
            str: 国家名称，如果城市不存在则返回None
        """
        city_info = cls.get_city_info(city_name)
        return city_info.get("Country") if city_info else None


    @classmethod
    def get_country_city_list(cls, country_name):
        """
        根据国家名称获取所在国家的城市列表
        
        Args:
            country_name (str): 国家名称（中文）
            
        Returns:
            list: 城市名称列表，如果国家不存在则返回 []
        """
        city_list = cls._country_data.get(country_name)
        return city_list if isinstance(city_list, list) else []
